package org.example;

public class Test2 {
    //leetcode 旋转矩阵
    //https://leetcode.cn/problems/rotate-image/description/?envType=study-plan-v2&envId=top-interview-150
    public void rotate(int[][] matrix) {
        int n = matrix.length;
        int leftBorder = 0, rightBorder = n-1, topBorder = 0, bottomBorder = n-1;
        for (int i = 0; i < n/2; i++) {
            int index = 0;
            while (leftBorder + index < rightBorder) {
                int tmp = matrix[topBorder][leftBorder+index];
                matrix[topBorder][leftBorder + index] = matrix[bottomBorder-index][leftBorder];
                matrix[bottomBorder-index][leftBorder] = matrix[bottomBorder][rightBorder-index];
                matrix[bottomBorder][rightBorder-index] = matrix[topBorder+index][rightBorder];
                matrix[topBorder+index][rightBorder] = tmp;
                index++;
            }
            leftBorder++;
            rightBorder--;
            topBorder++;
            bottomBorder--;
        }
    }

    public static void main(String[] args) {
        int[][] matrix = new int[4][4];
        int count = 1;
        for (int i = 0; i < 4; i++) {
            for (int j = 0; j < 4; j++) {
                matrix[i][j] = count++;
            }
        }
        Test2 test2 = new Test2();
        test2.rotate(matrix);
        System.out.println(555);
    }
}
